package com.ehotting.edsta.mqbd.test.zw.config;

import com.ehotting.mqbd.api.MQDBConstants;
import com.ehotting.edsta.mqbd.api.enums.SysModuleEnum;
import com.ehotting.mqbd.core.service.MQService;
import com.ehotting.mqbd.api.bean.MqApplicationContext;
import com.ehotting.mqbd.core.config.MqbdCorePropertyConfig;
import com.ehotting.mqbd.core.helper.IPHelper;
import com.ehotting.mqbd.core.helper.MQStringHelper;
import com.ehotting.mqbd.core.logger.MQSendLogger;
import com.ehotting.mqbd.core.mq.MessageProducer;
import com.ehotting.mqbd.core.manager.MsgStateManager;
import com.ehotting.mqbd.core.manager.SolverStateManager;
import com.ehotting.mqbd.core.sync.MqSyncFutureMapHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
public class MqbdZwCfg {

    @Autowired
    private IPHelper ipHelper;

    @DependsOn("mqbdCorePropertyConfig")
    @Bean(name ="messageProducer",initMethod = "start",destroyMethod = "shutdown")
    public MessageProducer concurrencyMessageProducer(MqApplicationContext mqApplicationContext,
                                                      MqbdCorePropertyConfig mqbdCorePropertyConfig)  {
        MessageProducer messageProducer = new MessageProducer(
                mqbdCorePropertyConfig.getProducer(),
                MQStringHelper.createProducerGroup(mqApplicationContext));
        return messageProducer;
    }

    @Bean(name="mqService")
    public MQService mqService(MqSyncFutureMapHelper mqSyncFutureMapHelper,
                               MessageProducer messageProducer,
                               MQSendLogger mqSendLogger, SolverStateManager solverStateManager){
        MQService MQService = new MQService();
        MQService.setLogger(mqSendLogger);
        MQService.setMessageProducer(messageProducer);
        MQService.setMqSyncFutureMapHelper(mqSyncFutureMapHelper);
        MQService.setSolverStateManager(solverStateManager);
        return MQService;
    }



    @Bean(name = "allContext")
    public MqApplicationContext allContext(){
        MqApplicationContext solverInfo = new MqApplicationContext();
        solverInfo.setLocalHost(ipHelper.getIp());
        solverInfo.setConsumerHost(MQDBConstants.DISPATCHER_HOST);
        solverInfo.setModule(SysModuleEnum.SIMULATION.getCode());
        return solverInfo;
    }





}